/*
 * Copyright © 2017-2023 TemplateFactory(xiaoymin@foxmail.com)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */


package com.github.xiaoymin.template.factory.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.github.xiaoymin.template.config.TemplateConfiguration;
import com.github.xiaoymin.template.core.TemplateContext;
import com.github.xiaoymin.template.render.TemplateFactoryRender;
import com.github.xiaoymin.template.render.aide.*;
import com.github.xiaoymin.template.render.plus.AideStoreConvertTemplateRender;
import com.github.xiaoymin.template.render.plus.AideStoreServiceImplPlusTemplateRender;
import com.github.xiaoymin.template.render.plus.AideStoreServicePlusTemplateRender;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author <a href="mailto:xiaoymin@foxmail.com">xiaoymin@foxmail.com</a>
 * 2022/7/15 15:54
 * @since template-factory 1.0
 */
public class V3StoreTemplateFactory extends AbstractTemplateFactory {
    
    @Override
    public String getAliasName() {
        return "V3CloudFactory";
    }
    
    @Override
    public Map<String, TemplateFactoryRender> getRenders() {
        Map<String, TemplateFactoryRender> map = new HashMap<>();
        map.put("add", new AideStoreAddTemplateRender());
        map.put("update", new AideStoreUpdateTemplateRender());
        map.put("search", new AideStoreSearchTemplateRender());
        map.put("dto", new AideStoreDtoTemplateRender());
        map.put("service", new AideStoreServicePlusTemplateRender());
        map.put("convert", new AideStoreConvertTemplateRender());
        map.put("serviceImpl", new AideStoreServiceImplPlusTemplateRender());
        map.put("controller", new AideStoreControllerTemplateRender());
        return map;
    }
    
    private Map<String, String> innerPathMap() {
        Map<String, String> map = new HashMap<>();
        map.put("add", "templates/v3Store/addVo.te");
        map.put("update", "templates/v3Store/updateVo.te");
        map.put("search", "templates/v3Store/searchVo.te");
        map.put("dto", "templates/v3Store/resultDTO.te");
        map.put("service", "templates/v3Store/service.te");
        map.put("convert", "templates/v3Store/convert.te");
        map.put("serviceImpl", "templates/v3Store/serviceImpl.te");
        map.put("controller", "templates/v3Store/controller.te");
        return map;
    }
    
    @Override
    public void apply(TemplateContext templateContext) {
        List<TemplateConfiguration> tmples = templateContext.getTemplateFactoryConfiguration().getTemplateConfigurations();
        if (CollectionUtil.isNotEmpty(tmples)) {
            for (TemplateConfiguration tmple : tmples) {
                tmple.setPath(innerPathMap().get(tmple.getAlias()));
                TemplateFactoryRender templateFactoryRender = getRender(tmple.getAlias());
                if (templateFactoryRender != null) {
                    templateFactoryRender.render(templateContext, tmple);
                }
            }
        }
    }
}
